package com.gome.ocean.service.datax.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.gome.ocean.dao.datax.ISQLUploadDAO;
import com.gome.ocean.dao.model.datasource.SQLUploadBean;
import com.gome.ocean.service.datax.ISQLUploadService;
import com.google.common.collect.Lists;

/**
 * @author zhangguoqing 2016年10月26日 下午8:31:44
 * @since 5.0.0
 */
@Service("sqlUploadServiceImpl")
public class SQLUploadServiceImpl implements ISQLUploadService {

    private final Logger LOG = LoggerFactory.getLogger(SQLUploadServiceImpl.class);

    @Autowired
    private ISQLUploadDAO iSqlUploadDao;

    @Override
    public boolean insert(SQLUploadBean bean) {
        boolean flag = false;
        try {
            iSqlUploadDao.insert(bean);
            flag = true;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return flag;
    }

    @Override
    public boolean update(SQLUploadBean bean) {
        boolean flag = false;
        try {
            iSqlUploadDao.update(bean);
            flag = true;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return flag;
    }

    @Override
    public boolean delete(Long id) {
        boolean flag = false;
        try {
            iSqlUploadDao.delete(id);
            flag = true;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return flag;
    }

    @Override
    public SQLUploadBean getBeanByMap(Map<String, Object> map) {
        SQLUploadBean bean;
        try {
            bean = iSqlUploadDao.getBeanByMap(map);
            return bean;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return null;
    }

    @Override
    public Page<SQLUploadBean> getListsBeanByMap(Map<String, Object> map, Integer pageNum, Integer pageSize) {
        List<SQLUploadBean> list = Lists.newArrayList();
        try {
            list = iSqlUploadDao.getListsBeanByMap(map, new RowBounds(pageNum, pageSize));
            return (Page<SQLUploadBean>) list;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return (Page<SQLUploadBean>) list;
    }

    @Override
    public Page<SQLUploadBean> getListsBeanByProjects(List<String> projects, String commitUserEmail, String startTime,
                                                      String endTime, Integer pageNum, Integer pageSize) {
        List<SQLUploadBean> list = Lists.newArrayList();
        try {
            list = iSqlUploadDao.getListsBeanByProjects(projects,
                commitUserEmail,
                startTime,
                endTime,
                new RowBounds(pageNum, pageSize));
            return (Page<SQLUploadBean>) list;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return (Page<SQLUploadBean>) list;
    }

    @Override
    public Page<SQLUploadBean> getAllListsBean(Integer pageNum, Integer pageSize) {
        List<SQLUploadBean> list = Lists.newArrayList();
        try {
            list = iSqlUploadDao.getAllListsBean(new RowBounds(pageNum, pageSize));
            return (Page<SQLUploadBean>) list;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return (Page<SQLUploadBean>) list;
    }

}
